<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="execte">点击我执行命令</button>
<button id="undo">点击我执行命令</button>
<script>
  var Tv = {
      open:function () {
          console.log('打开电视机');
      },
      close:function () {
          console.log('关闭电视机');
      }
  }
  var createCommand = function (receive) {
     var execute = function () {
         return receive.open();
     }
     var undo = function () {
         return receive.close();
     }
     return{
         execute:execute,
         undo:undo
     }
  }
  var setCommand = function (command) {
      document.getElementById('execte').onclick=function () {
          command.execute()
      }
      document.getElementById('undo').onclick=function () {
          command.undo()
      }
  }
  setCommand(createCommand(Tv));
</script>
</body>
</html>